package com.china08.yxyapi.api.manage.sch.platform.attendance.setting;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.attendance.YxyYxyTecAttendanceConfig;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.attendance.YxyTecAttendanceConfigRepository;

import io.swagger.annotations.ApiOperation;

@CrossOrigin
@RestController
public class AttendAnceSettingSchController extends YxyApiBaseController {

    @Autowired
    YxyTecAttendanceConfigRepository yxyTecAttendanceConfigRepository;

    @ApiOperation("设置考勤配置")
    @RequestMapping(value = "/api_yw/manage/sch/platform/attendance/setting/sch", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel precess(HttpServletRequest request, HttpServletResponse response) {

        String schoolId = getProfile(request, response).getSchoolId();

        RespModel respModel = new RespModel();
        // 学校配饰
        YxyYxyTecAttendanceConfig yxyTecAttendanceConfig = yxyTecAttendanceConfigRepository.findBySchoolId(schoolId);

        if (null != yxyTecAttendanceConfig) {
            respModel.latitude = yxyTecAttendanceConfig.getLatitude();
            respModel.longitude = yxyTecAttendanceConfig.getLongitude();
            respModel.distance = yxyTecAttendanceConfig.getDistance();
            respModel.gateway = yxyTecAttendanceConfig.getGateway();
            respModel.times = yxyTecAttendanceConfig.getTimes();
            if (yxyTecAttendanceConfig.getClock1() != null && yxyTecAttendanceConfig.getClock1() instanceof Date) {
                respModel.clock1 = yxyTecAttendanceConfig.getClock1().getTime();
            }
            if (yxyTecAttendanceConfig.getClock2() != null && yxyTecAttendanceConfig.getClock2() instanceof Date) {
                respModel.clock2 = yxyTecAttendanceConfig.getClock2().getTime();
            }
            if (yxyTecAttendanceConfig.getTimes().equals("4")) {
                if (yxyTecAttendanceConfig.getClock3() != null && yxyTecAttendanceConfig.getClock3() instanceof Date) {
                    respModel.clock3 = yxyTecAttendanceConfig.getClock3().getTime();
                }
                if (yxyTecAttendanceConfig.getClock4() != null && yxyTecAttendanceConfig.getClock4() instanceof Date) {
                    respModel.clock4 = yxyTecAttendanceConfig.getClock4().getTime();
                }
            }
            respModel.winterVacationBegin = yxyTecAttendanceConfig.getWinterVacationBegin();
            respModel.winterVacationEnd = yxyTecAttendanceConfig.getWinterVacationEnd();
            respModel.summerVacationBegin = yxyTecAttendanceConfig.getSummerVacationBegin();
            respModel.summerVacationEnd = yxyTecAttendanceConfig.getSummerVacationEnd();
            respModel.monday = yxyTecAttendanceConfig.getMonday();
            respModel.tuesday = yxyTecAttendanceConfig.getTuesday();
            respModel.wednesday = yxyTecAttendanceConfig.getWednesday();
            respModel.thursday = yxyTecAttendanceConfig.getThursday();
            respModel.friday = yxyTecAttendanceConfig.getFriday();
            respModel.saturday = yxyTecAttendanceConfig.getSaturday();
            respModel.sunday = yxyTecAttendanceConfig.getSunday();
        }
        return respModel;
    }

    protected static class ReqModel extends YxyApiReqModel {

    }

    protected static class RespModel extends YxyApiRespModel {
        public Double latitude;
        public Double longitude;
        public Integer distance;
        public String times = "2";
        public String gateway = "";
        public long clock1 = 0L;
        public long clock2 = 0L;
        public long clock3 = 0L;
        public long clock4 = 0L;
        public Date winterVacationBegin = null;
        public Date winterVacationEnd = null;
        public Date summerVacationBegin = null;
        public Date summerVacationEnd = null;
        public boolean monday = true;
        public boolean tuesday = true;
        public boolean wednesday = true;
        public boolean thursday = true;
        public boolean friday = true;
        public boolean saturday = false;
        public boolean sunday = false;
    }
}
